//
//  OfflineTableViewController.m
//  BJS151148_ TeamProject_Travel
//
//  Created by lanou3g on 16/3/22.
//  Copyright © 2016年 lanou3g. All rights reserved.
//



/**离线页面*/


#import "OfflineTableViewController.h"
#import "DestinationTableViewController.h"
#import "StrategyDetailTableViewCell.h"
#import "RouteTableViewController.h"
#import "StrTableViewController.h"
#import "SpeTableViewController.h"
#import "UIImageView+WebCache.h"
#import "strategyModel.h"
#import "CDHttpHelper.h"
@interface OfflineTableViewController ()

@end

@implementation OfflineTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self.tableView registerNib:[UINib nibWithNibName:@"StrategyDetailTableViewCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"strategyDetail"];
    
    self.tableView.bounces = NO;
    self.tableView.showsVerticalScrollIndicator = NO;
}



#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    StrategyDetailTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"strategyDetail" forIndexPath:indexPath];
    if (cell == nil) {
        cell = [[StrategyDetailTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"strategyDetail"];
    }
    strategyModel *strModel = self.dataArray[indexPath.row];
    [cell.backImageView sd_setImageWithURL:[NSURL URLWithString:strModel.image_url]];
    cell.titleLabel.font = [UIFont systemFontOfSize:20];
    //    cell.titleLabel.backgroundColor = [UIColor colorWithRed:0.1 green:0.1 blue:0.1 alpha:0.6];
    cell.titleLabel.textColor = [UIColor orangeColor];
    NSString *str = [strModel.name_zh_cn stringByAppendingString:[NSString stringWithFormat:@" %@",strModel.name_en]];
    
    cell.titleLabel.text = str;
    [cell.strategyButton addTarget:self action:@selector(pushToStrategy:) forControlEvents:UIControlEventTouchUpInside];
    [cell.routeButton addTarget:self action:@selector(pushToRoute:) forControlEvents:UIControlEventTouchUpInside];
    [cell.destinationButton addTarget:self action:@selector(pushToDestinatioin:) forControlEvents:UIControlEventTouchUpInside];
    [cell.specialButton addTarget:self action:@selector(pushToSpecial:) forControlEvents:UIControlEventTouchUpInside];
    
    [cell.downloadButton removeFromSuperview];
    
    cell.strategyButton.tag = indexPath.row;
    cell.routeButton.tag = indexPath.row;
    cell.destinationButton.tag = indexPath.row;
    cell.specialButton.tag = indexPath.row;
    return cell;
}

- (void)pushToStrategy:(UIButton *)sender{
    StrTableViewController *strVC = [[StrTableViewController alloc]init];
    strategyModel *model = self.dataArray[sender.tag];
    strVC.ID = model.id;
    [self.navigationController pushViewController:strVC animated:YES];
}

- (void)pushToRoute:(UIButton *)sender{
    RouteTableViewController *routeVC = [[RouteTableViewController alloc]init];
    strategyModel *model = self.dataArray[sender.tag];
    routeVC.ID = model.id;
    routeVC.name = model.name_zh_cn;
    [self.navigationController pushViewController:routeVC animated:YES];
}

- (void)pushToDestinatioin:(UIButton *)sender{
    
    DestinationTableViewController *desVC = [[DestinationTableViewController alloc]init];
    strategyModel *model = self.dataArray[sender.tag];
    desVC.strategyModel = model;
    desVC.strategyModel.lat = model.lat;
    desVC.strategyModel.lng = model.lng;
    for (strategyModel *strModel in self.dataArray) {
        [desVC.numArray addObject:strModel.name_zh_cn];
    }
    strategyModel *model1 = self.dataArray[0];
    desVC.content_count = model1.contents_count;
    [self.navigationController pushViewController:desVC animated:YES];
    
}

- (void)pushToSpecial:(UIButton *)sender{
    
    SpeTableViewController *speVC = [[SpeTableViewController alloc]init];
    strategyModel *model = self.dataArray[sender.tag];
    speVC.id = model.id;
    
    [self.navigationController pushViewController:speVC animated:YES];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return [UIScreen mainScreen].bounds.size.height / 2;
}


@end
